using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientInformationController : Controller
    {
		private readonly IPatientRepository patientRepository;
		private readonly IPatientInformationRepository patientinformationRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientInformationController()// : this(new PatientRepository(), new PatientInformationRepository())
        {
            patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            patientinformationRepository = Registry.RepositoryFactory.GetPatientInformationRepository();
        }

        public PatientInformationController(IPatientRepository patientRepository, IPatientInformationRepository patientinformationRepository)
        {
			this.patientRepository = patientRepository;
			this.patientinformationRepository = patientinformationRepository;
        }

        //
        // GET: /PatientInformation/

        public ViewResult Index()
        {
            return View(patientinformationRepository.All);//Including(patientinformation => patientinformation.Patient));
        }

        //
        // GET: /PatientInformation/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patientinformationRepository.Find(id));
        }

        //
        // GET: /PatientInformation/Create

        public ActionResult Create()
        {
			ViewBag.PossiblePatients = patientRepository.All;
            return View();
        } 

        //
        // POST: /PatientInformation/Create

        [HttpPost]
        public ActionResult Create(PatientInformation patientinformation)
        {
            if (ModelState.IsValid) {
                patientinformationRepository.Create(patientinformation);
                patientinformationRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientInformation/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossiblePatients = patientRepository.All;
             return View(patientinformationRepository.Find(id));
        }

        //
        // POST: /PatientInformation/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientInformation patientinformation)
        {
            if (ModelState.IsValid) {
                patientinformationRepository.Update(patientinformation);
                patientinformationRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientInformation/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patientinformationRepository.Find(id));
        }

        //
        // POST: /PatientInformation/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pinfo = patientinformationRepository.Find(id);
            patientinformationRepository.Delete(pinfo);
            patientinformationRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

